package com.hns.can.master.service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.base.entity.SysParamInfoEntity;
import com.hns.can.base.entity.SysUserEntity;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.UtilString;

/**
 * 严重度设置 - 业务类
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */
@Service
public class SeverityService extends CommonService {

    /**
     * 严重度设置 - 获取该组织机构下的严重度设置信息，如果没有的话显示为默认的信息
     * @param paraMap
     * @return
     * @author:lan
     * @email:763836737@qq.com
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List<SysParamInfoEntity> searchSeverityInfo(Map<String, Object> paraMap) {
        List<SysParamInfoEntity> list = PubUtil.convertListMapToObject(
            this.sqlMapDao.selectList("severity.searchSeverityInfo", paraMap), SysParamInfoEntity.class);
        return list;
    }

    /**
     * 严重度设置 - 修改严重度信息
     * @param user
     * @param corpId
     * @param seleOrganId
     * @param currOrganId
     * @param paramIds
     * @param paramValues
     * @param paramValue2s
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
    @Transactional
    public void uptSeverityInfo(SysUserEntity user,String corpId,String seleOrganId, String currOrganId, 
                String[] paramIds, String[] paramValues, String[] paramValue2s) throws Exception {
        if(seleOrganId.equals(currOrganId)){ //更新已有的数据
            for(int i = 0; i < paramIds.length; i++){
                SysParamInfoEntity entity = this.commonEntityDao.find(paramIds[i], SysParamInfoEntity.class);
                entity.setParamValue(paramValues[i]);
                entity.setParamValue2(paramValue2s[i]);
                entity.setUpdateTime(new Date());
                entity.setUpdateUser(user.getAcctName());
                this.commonEntityDao.update(entity);
            }
        }else{ //添加新数据
            for(int i = 0; i < paramIds.length; i++){
                SysParamInfoEntity entity = this.commonEntityDao.find(paramIds[i], SysParamInfoEntity.class);
                SysParamInfoEntity dbentity = new SysParamInfoEntity();
                PubUtil.copyPropertiesInclude(entity, dbentity, new String[]{"paramTypeCode", "paramCode", "paramName", "paramType", "enabledSt"});
                dbentity.setParamId(UtilString.getUUID());
                dbentity.setOrganId(seleOrganId);
                dbentity.setParamValue(paramValues[i]);
                dbentity.setParamValue2(paramValue2s[i]);
                dbentity.setCrtTime(new Date());
                dbentity.setCrtUser(user.getAcctName());
                dbentity.setUpdateTime(new Date());
                dbentity.setUpdateUser(user.getAcctName());
                dbentity.setCorpId(corpId);
                this.commonEntityDao.save(dbentity);
            }
        }
    }
    
}
